<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="../backend/inc/taglibs.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>账号注册</title>
    <link rel="stylesheet" type="text/css" href="${contextPath}/static/threeVideo/css/style.css"/>
</head>
<body>
<div class="bg">
    <div class="logo"></div>
    <div class="content">
        <div class="input-box">
            <input type="text" id="mobile" placeholder='请输入手机号' maxlength="11"/>
            <div class="input-text" id="mobileError" style="display: none">*手机号格式不正确</div>
        </div>
        <div class="input-box">
            <input type="password" id="password" placeholder='请输入新密码' maxlength="20"/>
            <%--<div class="input-yan"></div>--%>
            <div class="input-text" id="passwordError" style="display: none">*至少6位数</div>
        </div>
        <div class="input-box">
            <input type="password" id="quePassword" placeholder='请确认新密码' maxlength="20"/>
            <%--<div class="input-yan"></div>--%>
            <div class="input-text" id="quePasswordError" style="display: none">*与之前密码不一致</div>
        </div>
        <div class="input-box">
            <input type="text" placeholder='请输入验证码' id="code" maxlength="6"/>
            <div class="yz-btn">获取验证码</div>
        </div>
        <div class="c-fw"><span class="c-fw-active" id="serviceConfirm"></span>我已阅读并同意三力视频的<a href="${contextPath}/company/serviceInfo">服务条款</a></div>
        <div class="c-btn" onclick="sendInfo()">确认</div>
        <a href="${contextPath}/company/login" class="c-a">返回登录</a>
    </div>
</div>

<script type="text/javascript" src="${contextPath}/static/threeVideo/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="${contextPath}/static/threeVideo/js/index.js"></script>
</body>

<script type="text/javascript">
    function sendCode() {
        if (!checkMobile($('#mobile').val())) {
            $('#mobileError').css('display', '');
            return false;
        } else {
            $('#mobileError').css('display', 'none');
            return true;
        }
    }

    function sendInfo() {
        var flag = true;
        var mobile = $('#mobile').val();
        var password = $('#password').val();
        var quePassword = $('#quePassword').val();
        var code = $('#code').val();

        if (!checkMobile(mobile)) {
            $('#mobileError').css('display', '');
            flag = false;
            return;
        } else {
            $('#mobileError').css('display', 'none');
        }

        if (null == password || password == '') {
            $('#passwordError').css('display', '');
            flag = false;
            return;
        } else {
            $('#passwordError').css('display', 'none');
        }

        if (quePassword != password) {
            $('#quePasswordError').css('display', '');
            flag = false;
            return;
        } else {
            $('#quePasswordError').css('display', 'none');
        }

        if (null == code || code == '') {
            alert('请输入验证码');
            flag = false;
            return;
        }

        if (!$('#serviceConfirm').is('.c-fw-active')) {
            alert('请仔细查看并同意服务条款');
            flag = false;
            return;
        }

        if (flag) {
            $.ajax({
                dataType: 'json',
                url: '${contextPath}/company/register',
                data: {
                    mobile: mobile,
                    password: password,
                    code: code
                },
                success: function (data) {
                    if (data == 1) {
                        alert('注册成功');
                        window.location.href = '${contextPath}/company/login';
                    } else if (data == -1) {
                        alert('手机号已存在');
                    } else if (data == -2) {
                        alert('验证码错误');
                    } else {
                        alert('注册失败');
                    }
                }
            });
        }
    }
</script>

</html>